﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace RenShiKaoQin.Account
{
    public partial class EditPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnEditPassword_Click(object sender, EventArgs e)
        {
            hrdbEntities ent = new hrdbEntities();
            string id = User.Identity.Name;
            var kqemps = from tkqemp in ent.TKQEmployees where tkqemp.FEmployeeID.Equals(id) select tkqemp;
            if (kqemps.Any())
            {
                TKQEmployee kqemp = kqemps.Single();
                if (kqemp.FPassword.Equals(tbOldPass.Text))
                {
                    if (tbNewPass.Text.Equals(tbConfirmPass.Text))
                    {
                        kqemp.FPassword = tbNewPass.Text;
                        ent.SaveChanges();
                        ClientScript.RegisterStartupScript(this.GetType(), "succeed", "alert('修改密码成功');", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "notmatch", "alert('两次输入的新密码不一致');", true);
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "wrongoldpass", "alert('输入的原密码错误');", true);
                }
            }
            ent.Dispose();
        }
    }
}